<?php

class AlertDetail extends CI_Controller {

    function AlertDetail() {
        parent::__construct();
		$this->load->model('ws/alerta_model');
		$this->load->model('ws/usuario_model');
        session_start();
        if (!$this->session->userdata('logged_in')) {
            $this->session->set_flashdata('error', 'Debe haberse logueado');
            redirect('login', 'refresh');
        }
    }
	
	public function index() {
		echo "alertDetail";
	}
	
	public function detail($idAlerta){
		
		$data['map'] = null;
		$data['title'] = "Detalle Alerta";
        $data['username'] = $this->session->userdata('username');
        $data['name'] = $this->session->userdata('name');
        $data['acceso'] = $this->session->userdata('acceso');
        $data['main'] = "pages/dashboard_detail.php"; //Ruta del contenido del home		
		$data['alerta'] = $this->alerta_model->get_alert_by_id($idAlerta);
		$idUsuario = $data['alerta']['idUsuario'];
		$data['user'] = $this->usuario_model->get_user_by_id($idUsuario);
		
        $this->load->vars($data);
		$this->load->view('user_views/dashboard_user_view');
	
	}
	
    public function index2() {
        //cargar las alertas
		$alertas = $this->alerta_model->get_all_alerts();	
		
		$this->load->library('googlemaps');
		$config['center'] = 'auto';
		$config['zoom'] = '14';
		//$config['cluster'] = TRUE;
		$this->googlemaps->initialize($config);
		
		foreach ($alertas as $alert){
			$marker = array();
			$marker['position'] = "".$alert['posicionY'].",".$alert['posicionX']."";
			$marker['infowindow_content'] = $alert['nombreTipoAlerta'];
			$marker['draggable'] = TRUE;
			$marker['ondblclick'] = 'show_confirm()';
			$marker['animation'] = 'DROP';
			$this->googlemaps->add_marker($marker);
		}
		
		$data['map'] = $this->googlemaps->create_map();	
		
        $data['title'] = "CityGuardian - Home";
        $data['username'] = $this->session->userdata('username');
        $data['name'] = $this->session->userdata('name');
        $data['acceso'] = $this->session->userdata('acceso');
        $data['main'] = "pages/dashboard_map.php"; //Ruta del contenido del home
		//$data['main'] = "pages/dashboard_content.php";
        $this->load->vars($data);
		$this->load->view('user_views/dashboard_map_view');
        //$this->load->view('user_views/dashboard_user_view');
        //echo "<script languaje='javascript'>alert('Index')</script>";
    }
	
	public function mostrarVista($idAlerta){
		$data['idAlerta']=$idAlerta;
		$this->load->view('templates/vista',$data);
	}
	
	public function vehicle(){
		
		
	}
	

    function logout() {
        $this->session->sess_destroy();
        $this->session->unset_userdata('logged_in');
        $this->session->set_flashdata('error', "Usted ha sido deslogueado!");
        redirect('login', 'refresh');
    }

}

?>
